package com.goodcol.plugin.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.intellij.database.model.DasColumn;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 从database插件的表生成时，构造的ColumnInfo对象
 *
 * @author 单红宇
 * @date 2024/2/1 12:11
 */
@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
public class DbColumnInfo extends ColumnInfo {

    /**
     * 原始对象
     */
    @JsonIgnore
    private final DasColumn obj;


    @Override
    public String getColumnName() {
        if(obj != null) {
            return obj.getName();
        }
        return "";
    }

    @Override
    public String getJdbcType() {
        if(obj != null) {
            return obj.getDasType().toDataType().typeName;
        }
        return "";
    }

    @Override
    public Integer getTypeLength() {
        if(obj != null) {
            return obj.getDasType().toDataType().getLength();
        }
        return -1;
    }

    @Override
    public Boolean getIsNotNull() {
        if(obj != null) {
            return obj.isNotNull();
        }
        return false;
    }

    @Override
    public String getOriginComment() {
        if(obj != null) {
            return obj.getComment();
        }
        return "";
    }

}
